<%@ page import="cn.school.service.StudentService" %>
<%@ page import="cn.school.entity.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="cn.school.util.StringKit" %>
<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: ghost
  Date: 2019/12/8
  Time: 18:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>学生信息</title>
    <script src="js/jquery-3.4.1.min.js"></script>
    <style>
        a{
          padding-left: 20px;
        }
    </style>
  </head>
  <body>
  <%@include file="checkLogin.jsp"%>
  <%
    String sname = StringKit.convertNull(request.getParameter("sname"));
    String tel = StringKit.convertNull(request.getParameter("tel"));
    String date = StringKit.convertNull(request.getParameter("enterdate"));
    Date enterdate = StringKit.format(date);
    String qq = StringKit.convertNull(request.getParameter("qq"));
    String url = "&sname="+sname+"&tel="+tel+"&enterdate="+date+"&qq"+qq;
    Object p = request.getParameter("pageNo");
    int pageNo = 1;
    if(p != null){
      pageNo = Integer.parseInt(p.toString());
    }
    StudentService ss = new StudentService();
    List<Student> list = ss.search(pageNo,10,sname,tel,qq,enterdate,null);
  %>
  <p>
    <form action="studentinfo.jsp">
    <input type="text" name="sname" value="<%=sname%>" placeholder="姓名">
    <input type="text" name="tel" value="<%=tel%>" placeholder="电话">
    入学日期：<input type="date" name="enterdate" value="<%=date%>">
    <input type="search" name="qq" value="<%=qq%>" placeholder="qq号">
    <input type="submit" value="search">
    </form>
  </p>
  <a href="addStudent.jsp">添加新生</a>
  <table border="1" cellspacing="0" cellpadding="10">
    <tr><td>姓名</td><td>性别</td><td>电话号码</td><td>qq</td><td>微信</td><td>所在班级</td><td>操作</td></tr>
<%
  for(Student s:list){
%>
    <tr><td><%=s.getSname()%></td><td><%=s.getSex()%></td><td><%=s.getTelephone()%></td>
      <td><%
        if(s.getQq()!=null){
            out.print(s.getQq());
        }else{
            out.print("");
        }
        %>
      </td><td><%=s.getWechat()%></td><td><%=s.getGname()%></td><td><a href="alterStudent.jsp?id=<%=s.getStuno()%>">修改</a>&nbsp;
        <a onclick="return window.confirm('确认删除？')" href="delstu.jsp?id=<%=s.getStuno()%>">删除</a></td></tr>
<%
  }
%>
  </table>
  <br/>
  <%--<%
    Integer count= ss.countStu()/10;
    if(pageNo != 1){
      out.print("<a href='changeLimit.jsp?pageNo=0'>上一页</a>");
    }
    for(int i=1;i<=count;i++){
        if(i == pageNo){
            out.print("\t第"+i+"页\t");
        }else{
            out.print("<a href='changeLimit.jsp?pageNo="+i+"'>\t第"+i+"页\t</a>");
        }
    }
    if(pageNo != count){
      out.print("<a href='changeLimit.jsp?pageNo=-1'>下一页</a>");
    }
  %>--%>
  <br>
  <%
   int count= ss.searchTotal(sname,tel,qq,enterdate,null)/10;
   int max = count + 1;
   if(count != 0){
      if(pageNo != 1){
        out.print("<a href='studentinfo.jsp?pageNo=1"+url+"'>首页</a>");
        out.print("<a href='studentinfo.jsp?pageNo="+(pageNo-1)+url+"'>上一页</a>");
      }
  %>
  <input type="text" name="go" style="width:35px;" value="<%=pageNo%>">/<%=max%>页
  <%
      if(pageNo != max){
        out.print("<a href='studentinfo.jsp?pageNo="+(pageNo+1)+url+"'>下一页</a>");
        out.print("<a href='studentinfo.jsp?pageNo="+max+url+"'>尾页</a>");
      }
    }
  %>
  </body>
<script>
  $(function(){
     $("input[name=go]").keydown(function(event){
         if(event.keyCode == 13){
             if(this.value==""||isNaN(this.value)){
                 return false;
             }
             window.location = "studentinfo.jsp?pageNo="+$(this).val()+<%=url%>;
         }
     }).blur(function(){
         if(this.value==""||isNaN(this.value)){
             return false;
         }
         window.location = "studentinfo.jsp?pageNo="+$(this).val()+<%=url%>;
     });
  });
</script>
</html>
